---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: my-nexus-pv
  labels:
    type: local
spec:
  storageClassName: nfs
  capacity:
    storage: 32Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/home/nexus"

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-nexus-pvc
  labels:
    type: local
spec:
  storageClassName: nfs
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 32Gi

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nexus
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nexus-server
  template:
    metadata:
      labels:
        app: nexus-server
    spec:
      initContainers:
        - name: chown-nexusdata-owner-to-nexus
          image: busybox:1.34.1
          command: [ "/bin/sh","-c" ]
          args: [ "chown -R 200:200 /nexus-data" ]
          volumeMounts:
            - name: nexus-nfs
              mountPath: /nexus-data
      containers:
        - name: nexus
          image: sonatype/nexus3:latest
          env:
            - name: NEXUS_SEARCH_INDEX_REBUILD_ON_STARTUP
              value: "true"
            - name: INSTALL4J_ADD_VM_PARAMS
              value: "-Xms2703m -Xmx2703m -XX:MaxDirectMemorySize=2703m -Djava.util.prefs.userRoot=/some-other-dir"
          resources:
            # requests:
            #   cpu: "1"
            #   memory: "512Mi"
            # limits:
            #   cpu: "2"
            #   memory: "4096Mi"
          ports:
            - containerPort: 8081
          volumeMounts:
            - name: nexus-nfs
              mountPath: /nexus-data
      volumes:
        - name: nexus-nfs
          persistentVolumeClaim:
            claimName: my-nexus-pvc

---
apiVersion: v1
kind: Service
metadata:
  name: nexus-service
  annotations:
      prometheus.io/scrape: 'true'
      prometheus.io/path:   /
      prometheus.io/port:   '8081'
spec:
  selector: 
    app: nexus-server
  type: NodePort  
  ports:
    - port: 8081
      targetPort: 8081
      nodePort: 32460